{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "d7429b93",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "from tensorflow.keras.experimental import WideDeepModel,LinearModel\n",
    "from keras.models import Sequential\n",
    "import numpy as np\n",
    "import levenberg_marquardt as lm\n",
    "import pandas as pd\n",
    "from itertools import product\n",
    "from keras import Model\n",
    "from tensorflow.keras.metrics import RootMeanSquaredError\n",
    "from keras.optimizers import Adam,SGD,Adagrad\n",
    "from keras.layers import Dense,Conv1D,Conv2D,Flatten,MaxPool1D,LeakyReLU,MaxPooling1D,BatchNormalization,Input,LSTM,normalization\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.preprocessing import MinMaxScaler,StandardScaler"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "01408bbb",
   "metadata": {},
   "outputs": [],
   "source": [
    "def import_dataset(normalised=True,scaleMethod='Standard'):\n",
    "    '''\n",
    "    Imports Dataset and returns either scaled values depending upon user inputs\n",
    "    \n",
    "    Input:\n",
    "        normalised -- boolean depending upon whether the user wants to scale the values\n",
    "        scaleMethod -- Type of scaler to be used if normalised is True\n",
    "    \n",
    "    Output:\n",
    "        (X_train,X_test,Y_train,Y_test) -- the training and testing dataset\n",
    "        scaler -- used to perform inverse transform if dataset is scaled\n",
    "    '''\n",
    "    data = pd.read_csv('Dataset/Static_Model/15000DwithQuat.csv')\n",
    "    dataS = data.drop('Unnamed: 0',axis=1)\n",
    "    \n",
    "    if normalised == False:\n",
    "        scaler = 'None'\n",
    "        X = dataS.iloc[:,:3].values\n",
    "        Y = dataS.iloc[:,7:].values\n",
    "#         scaler = MinMaxScaler(feature_range=(0,1))\n",
    "#         scaler.fit(X)\n",
    "#         X = scaler.transform(X)\n",
    "        X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.05,random_state=0)\n",
    "        \n",
    "        \n",
    "    elif scaleMethod == 'Standard':\n",
    "        scaler = StandardScaler()\n",
    "        scaler.fit(dataS)\n",
    "        dataS = scaler.transform(dataS)\n",
    "        X = dataS[:,:3]\n",
    "        Y = dataS[:,7:]\n",
    "        X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.15,random_state=0)\n",
    "    \n",
    "    elif scaleMethod == 'MinMax':\n",
    "        scaler = MinMaxScaler(feature_range=(0,1))\n",
    "        scaler.fit(dataS)\n",
    "        dataS = scaler.transform(dataS)\n",
    "        X = dataS[:,:3]\n",
    "        Y = dataS[:,7:]\n",
    "        X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.15,random_state=0)\n",
    "    \n",
    "    return X_train,X_test,Y_train,Y_test,scaler"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a48d959a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def inverseTransform(scaler,*arr):\n",
    "    '''\n",
    "    Used to perform Inverse Transformation on normalised dataset\n",
    "    \n",
    "    Input:\n",
    "        scaler -- Instance of Normaliser used\n",
    "        *arr -- list of arrays to be concatenated\n",
    "    '''\n",
    "    data = np.concatenate(arr,axis=1)\n",
    "    data = pd.DataFrame(data)\n",
    "    arrInverse = scaler.inverse_transform(data)\n",
    "    \n",
    "    return arrInverse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "0cb60d5c",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cost(y_test,y_pred):\n",
    "    '''\n",
    "    Calculates error of the model\n",
    "    '''\n",
    "    error = (y_test-y_pred)/y_test\n",
    "    error = np.sum(abs(error))/(y_test.shape[0]*y_test.shape[1])*100\n",
    "    \n",
    "    return error"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "86b51792",
   "metadata": {},
   "outputs": [],
   "source": [
    "def rmse(y_test,y_pred):\n",
    "    error = np.sum((y_test-y_pred)**2)\n",
    "    error = error/(y_test.shape[0]*y_test.shape[1])\n",
    "    error = math.sqrt(error)\n",
    "    return error"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "0893c305",
   "metadata": {},
   "outputs": [],
   "source": [
    "def errorMagnitude(y_true,y_pred):\n",
    "    \n",
    "    minMag = min([min(abs(i)) for i in y_true-y_pred])\n",
    "    maxMag = max([max(abs(i)) for i in y_true-y_pred])\n",
    "    \n",
    "    return (minMag,maxMag)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "3011e9c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cross_transformation(X,C):\n",
    "    phi = np.zeros(shape=X.shape)\n",
    "    for i in range(X.shape[1]):\n",
    "        phi[:,i] = X[:,i]**C[i]\n",
    "    phi = np.prod(phi,axis=1)\n",
    "    phi = phi.reshape(phi.shape[0],1)\n",
    "    phi = np.concatenate((X,phi),axis=1)\n",
    "    return phi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "360dbe95",
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train,X_test,Y_train,Y_test,scaler = import_dataset(scaleMethod='MinMax')\n",
    "X_trainD = X_train.reshape(X_train.shape[0],1,X_train.shape[1])\n",
    "X_testD = X_test.reshape(X_test.shape[0],1,X_test.shape[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "42ee4ebb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/50\n",
      "223/223 [==============================] - 0s 2ms/step - loss: 0.5438 - val_loss: 0.4904\n",
      "Epoch 2/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4868 - val_loss: 0.4848\n",
      "Epoch 3/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4856 - val_loss: 0.4845\n",
      "Epoch 4/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4853 - val_loss: 0.4842\n",
      "Epoch 5/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4850 - val_loss: 0.4838\n",
      "Epoch 6/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4847 - val_loss: 0.4835\n",
      "Epoch 7/50\n",
      "223/223 [==============================] - ETA: 0s - loss: 0.484 - 0s 1ms/step - loss: 0.4845 - val_loss: 0.4832\n",
      "Epoch 8/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4842 - val_loss: 0.4830\n",
      "Epoch 9/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4840 - val_loss: 0.4828\n",
      "Epoch 10/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4839 - val_loss: 0.4827\n",
      "Epoch 11/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4838 - val_loss: 0.4826\n",
      "Epoch 12/50\n",
      "223/223 [==============================] - ETA: 0s - loss: 0.483 - 0s 1ms/step - loss: 0.4837 - val_loss: 0.4825\n",
      "Epoch 13/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4837 - val_loss: 0.4824\n",
      "Epoch 14/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4836 - val_loss: 0.4824\n",
      "Epoch 15/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4836 - val_loss: 0.4824\n",
      "Epoch 16/50\n",
      "223/223 [==============================] - ETA: 0s - loss: 0.483 - ETA: 0s - loss: 0.483 - 0s 1ms/step - loss: 0.4835 - val_loss: 0.4823\n",
      "Epoch 17/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4835 - val_loss: 0.4823\n",
      "Epoch 18/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4835 - val_loss: 0.4823\n",
      "Epoch 19/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4834 - val_loss: 0.4822\n",
      "Epoch 20/50\n",
      "223/223 [==============================] - ETA: 0s - loss: 0.483 - 0s 1ms/step - loss: 0.4834 - val_loss: 0.4822\n",
      "Epoch 21/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4834 - val_loss: 0.4822\n",
      "Epoch 22/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4834 - val_loss: 0.4821\n",
      "Epoch 23/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4833 - val_loss: 0.4822\n",
      "Epoch 24/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4833 - val_loss: 0.4821\n",
      "Epoch 25/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4833 - val_loss: 0.4821\n",
      "Epoch 26/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4833 - val_loss: 0.4821\n",
      "Epoch 27/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4833 - val_loss: 0.4821\n",
      "Epoch 28/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4833 - val_loss: 0.4820\n",
      "Epoch 29/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4832 - val_loss: 0.4820\n",
      "Epoch 30/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4832 - val_loss: 0.4820\n",
      "Epoch 31/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4832 - val_loss: 0.4820\n",
      "Epoch 32/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4832 - val_loss: 0.4820\n",
      "Epoch 33/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4832 - val_loss: 0.4820\n",
      "Epoch 34/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4832 - val_loss: 0.4820\n",
      "Epoch 35/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4832 - val_loss: 0.4820\n",
      "Epoch 36/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4832 - val_loss: 0.4819\n",
      "Epoch 37/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4832 - val_loss: 0.4819\n",
      "Epoch 38/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4832 - val_loss: 0.4819\n",
      "Epoch 39/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4831 - val_loss: 0.4819\n",
      "Epoch 40/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4831 - val_loss: 0.4819\n",
      "Epoch 41/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4831 - val_loss: 0.4819\n",
      "Epoch 42/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4831 - val_loss: 0.4819\n",
      "Epoch 43/50\n",
      "223/223 [==============================] - ETA: 0s - loss: 0.483 - 0s 1ms/step - loss: 0.4831 - val_loss: 0.4819\n",
      "Epoch 44/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4831 - val_loss: 0.4818\n",
      "Epoch 45/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4831 - val_loss: 0.4819\n",
      "Epoch 46/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4831 - val_loss: 0.4818\n",
      "Epoch 47/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4831 - val_loss: 0.4818\n",
      "Epoch 48/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4831 - val_loss: 0.4818\n",
      "Epoch 49/50\n",
      "223/223 [==============================] - 0s 933us/step - loss: 0.4831 - val_loss: 0.4818\n",
      "Epoch 50/50\n",
      "223/223 [==============================] - 0s 1ms/step - loss: 0.4831 - val_loss: 0.4818\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<tensorflow.python.keras.callbacks.History at 0x1f751626700>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "encoding_dim = 200\n",
    "input_data = Input(shape=(7,))\n",
    "# \"encoded\" is the encoded representation of the input\n",
    "encoded = Dense(encoding_dim, activation='relu')(input_data)\n",
    "# \"decoded\" is the lossy reconstruction of the input\n",
    "decoded = Dense(7, activation='sigmoid')(encoded)\n",
    "\n",
    "# This model maps an input to its reconstruction\n",
    "autoencoder = Model(input_data, decoded)\n",
    "encoder = Model(input_data, encoded)\n",
    "\n",
    "encoded_input = Input(shape=(encoding_dim,))\n",
    "# Retrieve the last layer of the autoencoder model\n",
    "decoder_layer = autoencoder.layers[-1]\n",
    "# Create the decoder model\n",
    "decoder = Model(encoded_input, decoder_layer(encoded_input))\n",
    "autoencoder.compile(optimizer='adam', loss='binary_crossentropy')\n",
    "autoencoder.fit(X_train, X_train,\n",
    "                epochs=50,\n",
    "                batch_size=64,\n",
    "                shuffle=True,\n",
    "                validation_data=(X_test, X_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "51c43141",
   "metadata": {},
   "outputs": [],
   "source": [
    "encoded_imgs = encoder.predict(X_test)\n",
    "X_test_D = decoder.predict(encoded_imgs)\n",
    "encoded_imgs = encoder.predict(X_train)\n",
    "X_train_D = decoder.predict(encoded_imgs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "1afb2aee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/100\n",
      "200/200 [==============================] - 2s 12ms/step - loss: 0.1345 - accuracy: 0.3347 - root_mean_squared_error: 0.3667 - val_loss: 0.0835 - val_accuracy: 0.4960 - val_root_mean_squared_error: 0.2890\n",
      "Epoch 2/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0798 - accuracy: 0.5256 - root_mean_squared_error: 0.2825 - val_loss: 0.0741 - val_accuracy: 0.5996 - val_root_mean_squared_error: 0.2721\n",
      "Epoch 3/100\n",
      "200/200 [==============================] - 2s 10ms/step - loss: 0.0628 - accuracy: 0.6277 - root_mean_squared_error: 0.2507 - val_loss: 0.0533 - val_accuracy: 0.6693 - val_root_mean_squared_error: 0.2308\n",
      "Epoch 4/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0504 - accuracy: 0.6625 - root_mean_squared_error: 0.2244 - val_loss: 0.0513 - val_accuracy: 0.6698 - val_root_mean_squared_error: 0.2264\n",
      "Epoch 5/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0496 - accuracy: 0.6616 - root_mean_squared_error: 0.2228 - val_loss: 0.0508 - val_accuracy: 0.6636 - val_root_mean_squared_error: 0.2253\n",
      "Epoch 6/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0493 - accuracy: 0.6635 - root_mean_squared_error: 0.2219 - val_loss: 0.0505 - val_accuracy: 0.6813 - val_root_mean_squared_error: 0.2248\n",
      "Epoch 7/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0491 - accuracy: 0.6654 - root_mean_squared_error: 0.2216 - val_loss: 0.0505 - val_accuracy: 0.6676 - val_root_mean_squared_error: 0.2246\n",
      "Epoch 8/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0491 - accuracy: 0.6645 - root_mean_squared_error: 0.2215 - val_loss: 0.0503 - val_accuracy: 0.6747 - val_root_mean_squared_error: 0.2244\n",
      "Epoch 9/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0490 - accuracy: 0.6618 - root_mean_squared_error: 0.2213 - val_loss: 0.0504 - val_accuracy: 0.6680 - val_root_mean_squared_error: 0.2245\n",
      "Epoch 10/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0490 - accuracy: 0.6638 - root_mean_squared_error: 0.2213 - val_loss: 0.0503 - val_accuracy: 0.6658 - val_root_mean_squared_error: 0.2242\n",
      "Epoch 11/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0490 - accuracy: 0.6635 - root_mean_squared_error: 0.2213 - val_loss: 0.0509 - val_accuracy: 0.6756 - val_root_mean_squared_error: 0.2256\n",
      "Epoch 12/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0490 - accuracy: 0.6624 - root_mean_squared_error: 0.2213 - val_loss: 0.0501 - val_accuracy: 0.6716 - val_root_mean_squared_error: 0.2239\n",
      "Epoch 13/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0489 - accuracy: 0.6642 - root_mean_squared_error: 0.2212 - val_loss: 0.0502 - val_accuracy: 0.6822 - val_root_mean_squared_error: 0.2241\n",
      "Epoch 14/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0489 - accuracy: 0.6639 - root_mean_squared_error: 0.2211 - val_loss: 0.0503 - val_accuracy: 0.6733 - val_root_mean_squared_error: 0.2242\n",
      "Epoch 15/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0489 - accuracy: 0.6656 - root_mean_squared_error: 0.2210 - val_loss: 0.0501 - val_accuracy: 0.6689 - val_root_mean_squared_error: 0.2239\n",
      "Epoch 16/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0489 - accuracy: 0.6608 - root_mean_squared_error: 0.2212 - val_loss: 0.0501 - val_accuracy: 0.6609 - val_root_mean_squared_error: 0.2239\n",
      "Epoch 17/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0489 - accuracy: 0.6644 - root_mean_squared_error: 0.2211 - val_loss: 0.0501 - val_accuracy: 0.6716 - val_root_mean_squared_error: 0.2237\n",
      "Epoch 18/100\n",
      "200/200 [==============================] - ETA: 0s - loss: 0.0488 - accuracy: 0.6670 - root_mean_squared_error: 0.22 - 2s 8ms/step - loss: 0.0489 - accuracy: 0.6668 - root_mean_squared_error: 0.2211 - val_loss: 0.0501 - val_accuracy: 0.6716 - val_root_mean_squared_error: 0.2238\n",
      "Epoch 19/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0488 - accuracy: 0.6634 - root_mean_squared_error: 0.2210 - val_loss: 0.0502 - val_accuracy: 0.6711 - val_root_mean_squared_error: 0.2239\n",
      "Epoch 20/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0489 - accuracy: 0.6631 - root_mean_squared_error: 0.2211 - val_loss: 0.0506 - val_accuracy: 0.6671 - val_root_mean_squared_error: 0.2248\n",
      "Epoch 21/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0489 - accuracy: 0.6635 - root_mean_squared_error: 0.2212 - val_loss: 0.0501 - val_accuracy: 0.6787 - val_root_mean_squared_error: 0.2239\n",
      "Epoch 22/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6630 - root_mean_squared_error: 0.2210 - val_loss: 0.0501 - val_accuracy: 0.6640 - val_root_mean_squared_error: 0.2237\n",
      "Epoch 23/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0490 - accuracy: 0.6640 - root_mean_squared_error: 0.2213 - val_loss: 0.0507 - val_accuracy: 0.6724 - val_root_mean_squared_error: 0.2252\n",
      "Epoch 24/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6644 - root_mean_squared_error: 0.2210 - val_loss: 0.0501 - val_accuracy: 0.6627 - val_root_mean_squared_error: 0.2239\n",
      "Epoch 25/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0489 - accuracy: 0.6649 - root_mean_squared_error: 0.2211 - val_loss: 0.0501 - val_accuracy: 0.6636 - val_root_mean_squared_error: 0.2238\n",
      "Epoch 26/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0489 - accuracy: 0.6642 - root_mean_squared_error: 0.2212 - val_loss: 0.0502 - val_accuracy: 0.6716 - val_root_mean_squared_error: 0.2241\n",
      "Epoch 27/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6638 - root_mean_squared_error: 0.2210 - val_loss: 0.0502 - val_accuracy: 0.6822 - val_root_mean_squared_error: 0.2241\n",
      "Epoch 28/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0488 - accuracy: 0.6638 - root_mean_squared_error: 0.2210 - val_loss: 0.0502 - val_accuracy: 0.6787 - val_root_mean_squared_error: 0.2241\n",
      "Epoch 29/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0488 - accuracy: 0.6634 - root_mean_squared_error: 0.2210 - val_loss: 0.0501 - val_accuracy: 0.6658 - val_root_mean_squared_error: 0.2238\n",
      "Epoch 30/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6640 - root_mean_squared_error: 0.2210 - val_loss: 0.0502 - val_accuracy: 0.6716 - val_root_mean_squared_error: 0.2241\n",
      "Epoch 31/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6648 - root_mean_squared_error: 0.2209 - val_loss: 0.0503 - val_accuracy: 0.6756 - val_root_mean_squared_error: 0.2243\n",
      "Epoch 32/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0489 - accuracy: 0.6642 - root_mean_squared_error: 0.2210 - val_loss: 0.0502 - val_accuracy: 0.6716 - val_root_mean_squared_error: 0.2240\n",
      "Epoch 33/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6642 - root_mean_squared_error: 0.2210 - val_loss: 0.0507 - val_accuracy: 0.6622 - val_root_mean_squared_error: 0.2252\n",
      "Epoch 34/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0489 - accuracy: 0.6613 - root_mean_squared_error: 0.2210 - val_loss: 0.0503 - val_accuracy: 0.6640 - val_root_mean_squared_error: 0.2244\n",
      "Epoch 35/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0489 - accuracy: 0.6648 - root_mean_squared_error: 0.2211 - val_loss: 0.0504 - val_accuracy: 0.6707 - val_root_mean_squared_error: 0.2245\n",
      "Epoch 36/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0488 - accuracy: 0.6626 - root_mean_squared_error: 0.2208 - val_loss: 0.0502 - val_accuracy: 0.6604 - val_root_mean_squared_error: 0.2240\n",
      "Epoch 37/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0488 - accuracy: 0.6664 - root_mean_squared_error: 0.2208 - val_loss: 0.0502 - val_accuracy: 0.6676 - val_root_mean_squared_error: 0.2240\n",
      "Epoch 38/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0488 - accuracy: 0.6645 - root_mean_squared_error: 0.2209 - val_loss: 0.0501 - val_accuracy: 0.6782 - val_root_mean_squared_error: 0.2238\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 39/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0488 - accuracy: 0.6648 - root_mean_squared_error: 0.2208 - val_loss: 0.0502 - val_accuracy: 0.6640 - val_root_mean_squared_error: 0.2241\n",
      "Epoch 40/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6654 - root_mean_squared_error: 0.2209 - val_loss: 0.0501 - val_accuracy: 0.6618 - val_root_mean_squared_error: 0.2238\n",
      "Epoch 41/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6647 - root_mean_squared_error: 0.2209 - val_loss: 0.0502 - val_accuracy: 0.6738 - val_root_mean_squared_error: 0.2241\n",
      "Epoch 42/100\n",
      "200/200 [==============================] - 2s 10ms/step - loss: 0.0488 - accuracy: 0.6643 - root_mean_squared_error: 0.2210 - val_loss: 0.0501 - val_accuracy: 0.6653 - val_root_mean_squared_error: 0.2239\n",
      "Epoch 43/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6655 - root_mean_squared_error: 0.2208 - val_loss: 0.0502 - val_accuracy: 0.6658 - val_root_mean_squared_error: 0.2241\n",
      "Epoch 44/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0489 - accuracy: 0.6662 - root_mean_squared_error: 0.2211 - val_loss: 0.0501 - val_accuracy: 0.6707 - val_root_mean_squared_error: 0.2239\n",
      "Epoch 45/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6636 - root_mean_squared_error: 0.2209 - val_loss: 0.0501 - val_accuracy: 0.6658 - val_root_mean_squared_error: 0.2238\n",
      "Epoch 46/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0488 - accuracy: 0.6656 - root_mean_squared_error: 0.2209 - val_loss: 0.0501 - val_accuracy: 0.6787 - val_root_mean_squared_error: 0.2239\n",
      "Epoch 47/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0488 - accuracy: 0.6636 - root_mean_squared_error: 0.2209 - val_loss: 0.0501 - val_accuracy: 0.6609 - val_root_mean_squared_error: 0.2239\n",
      "Epoch 48/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6629 - root_mean_squared_error: 0.2208 - val_loss: 0.0504 - val_accuracy: 0.6724 - val_root_mean_squared_error: 0.2245\n",
      "Epoch 49/100\n",
      "200/200 [==============================] - 2s 10ms/step - loss: 0.0488 - accuracy: 0.6617 - root_mean_squared_error: 0.2209 - val_loss: 0.0501 - val_accuracy: 0.6640 - val_root_mean_squared_error: 0.2239\n",
      "Epoch 50/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0488 - accuracy: 0.6648 - root_mean_squared_error: 0.2209 - val_loss: 0.0501 - val_accuracy: 0.6604 - val_root_mean_squared_error: 0.2238\n",
      "Epoch 51/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0489 - accuracy: 0.6657 - root_mean_squared_error: 0.2211 - val_loss: 0.0501 - val_accuracy: 0.6680 - val_root_mean_squared_error: 0.2237\n",
      "Epoch 52/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0487 - accuracy: 0.6642 - root_mean_squared_error: 0.2208 - val_loss: 0.0502 - val_accuracy: 0.6756 - val_root_mean_squared_error: 0.2240\n",
      "Epoch 53/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0488 - accuracy: 0.6621 - root_mean_squared_error: 0.2208 - val_loss: 0.0501 - val_accuracy: 0.6764 - val_root_mean_squared_error: 0.2237\n",
      "Epoch 54/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6625 - root_mean_squared_error: 0.2209 - val_loss: 0.0502 - val_accuracy: 0.6756 - val_root_mean_squared_error: 0.2240\n",
      "Epoch 55/100\n",
      "200/200 [==============================] - 2s 9ms/step - loss: 0.0488 - accuracy: 0.6616 - root_mean_squared_error: 0.2209 - val_loss: 0.0503 - val_accuracy: 0.6716 - val_root_mean_squared_error: 0.2243\n",
      "Epoch 56/100\n",
      "200/200 [==============================] - 2s 8ms/step - loss: 0.0490 - accuracy: 0.6631 - root_mean_squared_error: 0.2213 - val_loss: 0.0502 - val_accuracy: 0.6653 - val_root_mean_squared_error: 0.2241\n",
      "Epoch 57/100\n",
      "200/200 [==============================] - 2s 10ms/step - loss: 0.0488 - accuracy: 0.6638 - root_mean_squared_error: 0.2209 - val_loss: 0.0500 - val_accuracy: 0.6791 - val_root_mean_squared_error: 0.2237\n",
      "Epoch 58/100\n",
      "  1/200 [..............................] - ETA: 0s - loss: 0.0452 - accuracy: 0.6406 - root_mean_squared_error: 0.2127"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-88-4a4b39c7422a>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     16\u001b[0m \u001b[0moptD\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mAdam\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0.001\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     17\u001b[0m \u001b[0mcombined_model\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcompile\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mopt\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moptD\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'mse'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mmetrics\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'accuracy'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mRootMeanSquaredError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 18\u001b[1;33m \u001b[0mcombined_model\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mlinear_X\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mX_trainD\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mY_train\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m64\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mepochs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m100\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mvalidation_data\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mlinear_Xt\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mX_testD\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mY_test\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m~\\anaconda3\\envs\\keras_env\\lib\\site-packages\\tensorflow\\python\\keras\\engine\\training.py\u001b[0m in \u001b[0;36m_method_wrapper\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m    106\u001b[0m   \u001b[1;32mdef\u001b[0m \u001b[0m_method_wrapper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    107\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_in_multi_worker_mode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m  \u001b[1;31m# pylint: disable=protected-access\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 108\u001b[1;33m       \u001b[1;32mreturn\u001b[0m \u001b[0mmethod\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    109\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    110\u001b[0m     \u001b[1;31m# Running inside `run_distribute_coordinator` already.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\envs\\keras_env\\lib\\site-packages\\tensorflow\\python\\keras\\engine\\training.py\u001b[0m in \u001b[0;36mfit\u001b[1;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)\u001b[0m\n\u001b[0;32m   1096\u001b[0m                 batch_size=batch_size):\n\u001b[0;32m   1097\u001b[0m               \u001b[0mcallbacks\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mon_train_batch_begin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstep\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1098\u001b[1;33m               \u001b[0mtmp_logs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtrain_function\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1099\u001b[0m               \u001b[1;32mif\u001b[0m \u001b[0mdata_handler\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshould_sync\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1100\u001b[0m                 \u001b[0mcontext\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0masync_wait\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\envs\\keras_env\\lib\\site-packages\\tensorflow\\python\\eager\\def_function.py\u001b[0m in \u001b[0;36m__call__\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m    778\u001b[0m       \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    779\u001b[0m         \u001b[0mcompiler\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"nonXla\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 780\u001b[1;33m         \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    781\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    782\u001b[0m       \u001b[0mnew_tracing_count\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_tracing_count\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\envs\\keras_env\\lib\\site-packages\\tensorflow\\python\\eager\\def_function.py\u001b[0m in \u001b[0;36m_call\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m    805\u001b[0m       \u001b[1;31m# In this case we have created variables on the first call, so we run the\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    806\u001b[0m       \u001b[1;31m# defunned version which is guaranteed to never create variables.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 807\u001b[1;33m       \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_stateless_fn\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[1;33m)\u001b[0m  \u001b[1;31m# pylint: disable=not-callable\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    808\u001b[0m     \u001b[1;32melif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_stateful_fn\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    809\u001b[0m       \u001b[1;31m# Release the lock early so that multiple threads can perform the call\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\envs\\keras_env\\lib\\site-packages\\tensorflow\\python\\eager\\function.py\u001b[0m in \u001b[0;36m__call__\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m   2827\u001b[0m     \u001b[1;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_lock\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2828\u001b[0m       \u001b[0mgraph_function\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkwargs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_maybe_define_function\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2829\u001b[1;33m     \u001b[1;32mreturn\u001b[0m \u001b[0mgraph_function\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_filtered_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m  \u001b[1;31m# pylint: disable=protected-access\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2830\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2831\u001b[0m   \u001b[1;33m@\u001b[0m\u001b[0mproperty\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\envs\\keras_env\\lib\\site-packages\\tensorflow\\python\\eager\\function.py\u001b[0m in \u001b[0;36m_filtered_call\u001b[1;34m(self, args, kwargs, cancellation_manager)\u001b[0m\n\u001b[0;32m   1841\u001b[0m       \u001b[0;31m`\u001b[0m\u001b[0margs\u001b[0m\u001b[0;31m`\u001b[0m \u001b[1;32mand\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m`\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;31m`\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1842\u001b[0m     \"\"\"\n\u001b[1;32m-> 1843\u001b[1;33m     return self._call_flat(\n\u001b[0m\u001b[0;32m   1844\u001b[0m         [t for t in nest.flatten((args, kwargs), expand_composites=True)\n\u001b[0;32m   1845\u001b[0m          if isinstance(t, (ops.Tensor,\n",
      "\u001b[1;32m~\\anaconda3\\envs\\keras_env\\lib\\site-packages\\tensorflow\\python\\eager\\function.py\u001b[0m in \u001b[0;36m_call_flat\u001b[1;34m(self, args, captured_inputs, cancellation_manager)\u001b[0m\n\u001b[0;32m   1921\u001b[0m         and executing_eagerly):\n\u001b[0;32m   1922\u001b[0m       \u001b[1;31m# No tape is watching; skip to running the function.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1923\u001b[1;33m       return self._build_call_outputs(self._inference_function.call(\n\u001b[0m\u001b[0;32m   1924\u001b[0m           ctx, args, cancellation_manager=cancellation_manager))\n\u001b[0;32m   1925\u001b[0m     forward_backward = self._select_forward_and_backward_functions(\n",
      "\u001b[1;32m~\\anaconda3\\envs\\keras_env\\lib\\site-packages\\tensorflow\\python\\eager\\function.py\u001b[0m in \u001b[0;36mcall\u001b[1;34m(self, ctx, args, cancellation_manager)\u001b[0m\n\u001b[0;32m    543\u001b[0m       \u001b[1;32mwith\u001b[0m \u001b[0m_InterpolateFunctionError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    544\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mcancellation_manager\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 545\u001b[1;33m           outputs = execute.execute(\n\u001b[0m\u001b[0;32m    546\u001b[0m               \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msignature\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    547\u001b[0m               \u001b[0mnum_outputs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_num_outputs\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\envs\\keras_env\\lib\\site-packages\\tensorflow\\python\\eager\\execute.py\u001b[0m in \u001b[0;36mquick_execute\u001b[1;34m(op_name, num_outputs, inputs, attrs, ctx, name)\u001b[0m\n\u001b[0;32m     57\u001b[0m   \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     58\u001b[0m     \u001b[0mctx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mensure_initialized\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 59\u001b[1;33m     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,\n\u001b[0m\u001b[0;32m     60\u001b[0m                                         inputs, attrs, num_outputs)\n\u001b[0;32m     61\u001b[0m   \u001b[1;32mexcept\u001b[0m \u001b[0mcore\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_NotOkStatusException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "lst = list(product([0, 1], repeat=7))\n",
    "linear_X = cross_transformation(X_train,lst[5])\n",
    "linear_Xt = cross_transformation(X_test,lst[5])\n",
    "linear_model = LinearModel()\n",
    "dnn_model = Sequential([LSTM(60,return_sequences=True),\n",
    "                        LSTM(60,return_sequences=True),\n",
    "                        LSTM(60,return_sequences=True),\n",
    "                        Conv1D(60,kernel_size=3,padding='same'),\n",
    "                        Conv1D(60,kernel_size=3,padding='same'),\n",
    "                        Conv1D(60,kernel_size=3,padding='same'),\n",
    "                        Flatten(),\n",
    "                        Dense(units=Y_train.shape[1],activation='relu')])\n",
    "\n",
    "combined_model = WideDeepModel(linear_model, dnn_model)\n",
    "opt = Adam(lr=0.001)\n",
    "optD = Adam(lr=0.001)\n",
    "combined_model.compile([opt, optD],'mse',metrics=['accuracy',RootMeanSquaredError()])\n",
    "combined_model.fit([linear_X, X_trainD], Y_train, 64,epochs=100,validation_data=([linear_Xt, X_testD], Y_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "03f17888",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"sequential_21\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "lstm_18 (LSTM)               (None, 1, 60)             16320     \n",
      "_________________________________________________________________\n",
      "conv1d_10 (Conv1D)           (None, 1, 60)             3660      \n",
      "_________________________________________________________________\n",
      "flatten_15 (Flatten)         (None, 60)                0         \n",
      "_________________________________________________________________\n",
      "dense_77 (Dense)             (None, 4)                 244       \n",
      "=================================================================\n",
      "Total params: 20,224\n",
      "Trainable params: 20,224\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "dnn_model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "785d765e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import mean_squared_error"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "7209bb2a",
   "metadata": {},
   "outputs": [],
   "source": [
    "Y_pred = combined_model.predict([linear_Xt, X_test_D])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "a9130e09",
   "metadata": {},
   "outputs": [],
   "source": [
    "true = inverseTransform(scaler,X_test,Y_test)\n",
    "pred = inverseTransform(scaler,X_test,Y_pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "8947ad02",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7.50790981060651"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mean_squared_error(true[:,7:],pred[:,7:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "12bf86bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.59977734, 0.6458354 , 0.282652  , 0.44842696],\n",
       "       [0.6019429 , 0.70274454, 0.30405182, 0.34978935],\n",
       "       [0.06303316, 0.41348943, 0.83542776, 0.65663517],\n",
       "       ...,\n",
       "       [0.6311    , 0.27082795, 0.30438918, 0.82601905],\n",
       "       [0.3557921 , 0.62786883, 0.540582  , 0.45214513],\n",
       "       [0.5753702 , 0.4319029 , 0.33860078, 0.663465  ]], dtype=float32)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Y_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "2a41cb46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.8336848 , 0.20802337, 0.57037049, 0.57303195],\n",
       "       [0.58373916, 0.49999831, 0.98172256, 0.98487204],\n",
       "       [0.37462883, 0.20746212, 0.77793236, 0.78074551],\n",
       "       ...,\n",
       "       [0.62537329, 0.79253548, 0.77811612, 0.78074552],\n",
       "       [0.58373723, 0.4581299 , 0.97858323, 0.98109021],\n",
       "       [0.29099131, 0.70900891, 0.80759774, 0.8109746 ]])"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c5fe962",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
